<script setup>
defineProps({
  modelValue: String,
  units: Array,
  label: String
});

defineEmits(['update:modelValue']);
</script>

<template>
  <div class="unit-selector">
    <label v-if="label">{{ label }}</label>
    <select
        :value="modelValue"
        @change="$emit('update:modelValue', $event.target.value)"
        class="select"
    >
      <option
          v-for="unit in units"
          :key="unit.name"
          :value="unit.name"
      >
        {{ unit.label }}
      </option>
    </select>
  </div>
</template>

<style scoped>
.unit-selector {
  display: flex;
  flex-direction: column;
  max-width: 10rem;
  margin-left: auto;
}

label {
  margin-bottom: 0.5rem;
  font-weight: bold;
}

.select {
  padding: -0.5rem;
  border-radius: 8px;
  color: #c2ffc7;
  background: #ffbece;
  border: 3px solid #c2ffc7;
  font-size:1.5rem;
}
</style>